#!/usr/bin/env python2.5
# encoding: utf-8

if not globals().has_key("esda"):
    execfile("esda.py")
    sys.exit()

init()
from StreamLoader import *
import time

videoDataFile = "zebra/video_data.csv"

class VideoTableLoader(CSVStreamLoader):
    def initializeStreams(self, values):
        self.streams.append(self.newStream("videos", "integer"))
    
    def insertIntoStreams(self, values):
        # YYYYMMDDHHMMSS
        startTime = time.mktime(time.strptime(values[2], "%Y%m%d%H%M%S"))
        
        values = [startTime, startTime + int(values[3]), (1 if values[4] == 'N' else 0) + (2 if values[5] == 'N' else 0) + 1]
        
        super(VideoTableLoader, self).insertIntoStreams(values)
    

print """
----
Starting IMPORT of %s
----
"""%videoDataFile

def filterCache(startTime, endTime, value):
    if value == 4:
        return 1
    else:
        return False

VideoTableLoader(newStream, videoDataFile).run()

newFilterStream("videosAffichees", "videos", filter=filterCache)
